<template>
  <div>
    <el-dialog
      title="快速审核"
      v-model="props.speedVisible"
      width="500px"
      append-to-body
      @close="speedCancel"
    >
      <el-form ref="speedFormRef" :model="queryParams">
        <el-form-item label="审核备注" prop="auditRemark">
          <el-input maxlength="300" v-model.trim="queryParams.auditRemark" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button type="primary" @click="handleSpeedSure('passed')"
          >通 过</el-button
        >
        <el-button type="danger" @click="handleSpeedSure('notPassed')"
          >不通过</el-button
        >
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import { ref, defineProps, defineEmits } from "vue";
const emits = defineEmits(["handleSpeedSure", "speedCancel"]);
const { proxy } = getCurrentInstance();
const props = defineProps({
  ids: {
    type: Array,
    default: [],
  },
  speedVisible: {
    type: Boolean,
    default: false,
  },
});


const queryParams = ref({
  ids: [],
  auditStatus: "", //审核状态
  auditRemark: "", //备注
});
const handleSpeedSure = (auditStatus) => {
  if (auditStatus === "notPassed" && !queryParams.value.auditRemark)
    return proxy.$modal.msgWarning(`备注不能为空`);
  proxy.$modal
    .confirm(`是否确认审核已选择的${props.ids.length}个商品`)
    .then(() => {
      queryParams.value.ids = props.ids;
      queryParams.value.auditStatus = auditStatus;
      product.draft
        .productdraftAudit({
          data: queryParams.value,
        })
        .then((res) => {
          if (res.code === 200) {
            proxy.resetForm("speedFormRef");
            emits("handleSpeedSure");
            proxy.$modal.msgSuccess(`操作成功`);
          }
        });
    });
};

const speedCancel = () => {
  proxy.resetForm("speedFormRef");
  emits("speedCancel");
};
</script>